package com.daling.product_processor.controller;


import com.daling.common.Result;
import com.daling.product_processor.ProductProcessor;
import com.daling.product_processor.common.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(tags = "不同平台品牌下-V3商品数据处理")
@RequestMapping("/product/processor/v3")
@Slf4j
public class ProductProcessorController {


    @ApiOperation("测试")
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test() {
        System.out.println("hello");
        return "hello danni";
    }

    @ApiOperation("商品数据处理")
    @RequestMapping(value = "/")
    public Result queryPrice(@Valid ProductProcessor productProcessor, BindingResult results) {
        Result result = new Result("");
        try {
            if (results.hasErrors()) {
                result.setMessage(results.getFieldError().getDefaultMessage());
            } else {
                // 调用service层
                result.setCode(CodeEnum.SUCCESS.getCode());
                result.setMessage(CodeEnum.SUCCESS.getMsg());
                result.setSuccess(true);
            }
        } catch (Exception e) {
            result.setData(e.toString());
        } finally {
            return result;
        }
    }



}
